﻿using Dal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Vote.Models;

namespace Bll
{
   public class BllSYJCommon
    {
       private static readonly DalSYJCommon dal = new DalSYJCommon();

       /// <summary>
       /// 新增实体表
       /// </summary>
       /// <param name="obj"></param>
       /// <returns></returns>
       public static int AddNewEntity<T>(string tableName,T obj ) where T : class
       {
           return dal.AddNewEntity<T>(tableName,obj);
       }

       /// <summary>
       /// 通过id删除某一条信息
       /// </summary>
       /// <param name="tableName"></param>
       /// <param name="id"></param>
       /// <returns></returns>
       public static int DeleteEntity<T>(string tableName, long id) where T : class
       {
           return dal.DeleteEntity<T>(tableName, id);
       }


       /// <summary>
       /// 删除实体类
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="tableName"></param>
       /// <param name="sql"></param>
       public static int DeleteEntityBySql(string tableName, string sql)
       {
           return dal.DeleteEntityBySql(tableName, sql);
       }


       /// <summary>
       /// 修改实体类
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="obj"></param>
       /// <param name="tableName"></param>
       public static int UpdateEntity<T>(string tableName,T obj) where T : class
       {
           return dal.UpdateEntity<T>(tableName,obj);
       }

       /// <summary>
       /// 更新实体类
       /// </summary>
       /// <param name="tableName"></param>
       /// <param name="sql"></param>
       public static int UpdateEntityBySql(string tableName, string sql)
       {
           return dal.UpdateEntityBySql(tableName, sql);
       }

       /// <summary>
       /// 查询实体类
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="tableName"></param>
       /// <param name="id"></param>
       /// <returns></returns>
       public static T SelectEntity<T>(string tableName, long id) where T : class
       {
           return dal.SelectEntity<T>(tableName, id);
       }
       public static int GetCountBySQL(string tableName, string sql)
       {
           return dal.GetCountBySQL(tableName, sql);
       }
       /// <summary>
       /// 查询实体类
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="tableName"></param>
       /// <param name="sql"></param>
       /// <returns></returns>
       public static List<T> SelectEntityBySql<T>(string tableName, string sql) where T : class
       {
           return dal.SelectEntityBySql<T>(tableName, sql);
       }

       /// <summary>
       /// 获取用户自定义字段
       /// </summary>
       /// <param name="tableName"></param>
       /// <param name="sql">只能获取一个字段,这个字段可以返回单个值也可以返回一列值</param>
       /// <param name="type">基本类型 如 string int long bool decimal</param>
       /// <param name="isList">是否返回列表 true:返回一列  false:单个值</param>
       /// <returns></returns>
       public static Object SelectSingleValueBySql(string tableName, string sql, string type = "string", bool isList = false)
       {
           return dal.SelectSingleValueBySql(tableName, sql, type, isList);
       }
       /// <summary>
       /// 分页获取
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="tableName"></param>
       /// <param name="conditionFiledValue"></param>
       /// <param name="currentPage"></param>
       /// <param name="pageSize"></param>
       /// <param name="orderByFiled"></param>
       /// <param name="desc"></param>
       /// <param name="totalPage"></param>
       /// <returns></returns>
       public static List<T> SelectEntityInfoByQueryWithPager<T>(string tableName, Dictionary<string, string> conditionFiledValue, int currentPage, int pageSize, string orderByFiled, bool desc, out int totalPage) where T : new()
       {
           return dal.SelectEntityInfoByQueryWithPager<T>(tableName, conditionFiledValue, currentPage, pageSize, orderByFiled, desc, out totalPage);
       }
    }
}
